to remove/FunctionsTOrun.R

# this file contains several functions which are needed in the analysis

#** calculate OR and its SE
createORreference.fun=function(r,n)
{

  logOR=c(0)
  selogOR=c(NA)

  for(i in 2:c(length(n)))
  {
    calculate=metabin(r[i],n[i],r[1],n[1],sm="OR")
    logOR=c(logOR,calculate$TE)
    selogOR=c(selogOR,calculate$seTE)

  }
  return(cbind(logOR=logOR,selogOR=selogOR))
}



































# #this function clears the data out of problems:
# #dataset <- antidep
# cleandosresdata.fun=function(dataset,nametoexclude="toexclude") # ,studyid,logRR,r,n,dose
# {
#   # this function takes a database and exclude studies that will cause problemsin fiting the dosres model for a particular outcome
#   # It return the same database but in the end it has a variable that tells you which studies to exclude
#   # Give a name to that column in the nametoexclude variable
#   originaldimension=dim(dataset)[2]
#   r=eval(substitute(r), dataset)
#   dose=eval(substitute(dose), dataset)
#   n=eval(substitute(n), dataset)
#   studyid=eval(substitute(studyid), dataset)
#
#   #exlude missing logOR: NO need as OR will be NA if r or n is NA
#   # out0=unique(studyid[is.na(logOR)])
#
#   # 1. exclude studies with NA events
#   out1=unique(studyid[is.na(r)])
#
#   # 2. exclude studies with  NA sample size
#   out2=unique(studyid[is.na(n)])
#
#   # 3. exclude those studies with the same dose in all arms
#   out3=unique(studyid)[tapply(dose,studyid,max)==tapply(dose,studyid,min)]
#
#   # 4. exclude those studies with NA dose
#   #nrow(antidep[is.na(dose),])/nrow(antidep) # 20% of studies are excluded because they did not report the dose-level
#   out4=unique(studyid[is.na(dose)])
#   #antidep$studyid[is.na(antidep$dose)]
#   # 5. exclude single arm studies:
#   # different function as we need to identify the single arm trials if NA is removed from data
#
#   # add column to the dataframe with a reason of exclusion: do it later
#
#   # add column with include/exclude studies T/F
#   dataset$exclude <- ifelse(studyid%in%c(out1,out2,out3,out4),TRUE,FALSE)
#   # toexclude=as.data.frame(studyid%in%c(out0,out1,out2,out3))
#   # names(toexclude)=c(nametoexclude)
#   dataset
# }
#
# exludesinglearmsdata.fun<-function(dataset,studyid)
# {
#   # the dataset to correct dataset
#   # studyid: defining the name of the studyid column
#   studyid=eval(substitute(studyid), dataset)
#   singlearmstudies=names(table(studyid))[table(studyid)<2]
#   dataset2=dataset[is.na(match(studyid,singlearmstudies)),]
#   dataset2
#   #returns a dataset with the same columns after excluding single arms
# }
#
#
htx-r/doseresNMA documentation built on Jan. 28, 2021, 5:32 a.m.